﻿using System;
using System.Net;
using pub.NET20Fix;

namespace gtasks.Utils
{
    public class AsyncUtils
    {
        public static void FireOnException(Action<Exception> eventDelegate, 
            Exception e, bool inDispatcher = true)
        {
            var we = e as WebException;
            if (we != null && we.Status == WebExceptionStatus.RequestCanceled)
            {
                return;
            }
            var handler = eventDelegate;
            if (handler != null)
            {
                if (inDispatcher)
                {
                    Dispatcher.Current.Invoke(() => handler(e));
                }
                else
                {
                    handler(e);
                }
            }
        } 
    }
}